-
-
Notifications
You must be signed in to change notification settings - Fork 858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] base_location: relax sql constraint #1020
Conversation
It was on purpose. Are you saying that you have in the same state cities with the exact same name? |
Jep, we do have the same name with serveral zip codes. |
But then use the same city and put those different zipcodes inside the city. |
The problem not doing this way is the denormalized data structure if not done this way. The layout is:
|
Hmm, but Odoo Core has the Is there a reason why |
This module changes the core structure to follow the one listed above, as we want to have an unique entity |
I got that, but I don't get why we can't leave it logically as it is and extend it for our purpose...and if someone is not filling up I will come back with more insights if you don't turn it down already yet 😉 |
With this module, zipcode is basically useless, so I'm afraid although we change this constraint, it won't serve you, but I'll wait more insights. |
Alright Pedro, I think I have now the full insight and I do understand that Nevertheless, I would think it is no mistake to relax the constraint to I know that you are straight with your opinions but maybe you could consider the PoV of the ones like me who want to keep it in line with upstream data (possibility to move back and forth without pain) and do not keep and enforce this breaking constraint. Maybe there are others who want to follow my argument and back it here, but let me say: "SQL constraints suck anyway" 😜 |
Just my five cents: I'd prefer the solution from Wolfgang too. The restriction is still pretty good and it solves the issue with cities that have the same same. |
Well, I still don't understand if this module hides all that part, why do you still wants to relax in it the constraint. It's fighting against the current. And if you plan to extend it someway, do you know that you can inherit the SQL constraint for changing it? |
Inherit by overriding? I guess so, but I was probably just triggered that this measure is/was too extreme and I understand the idea behind enforcing the user itself. So yeah, no issue with this not being merged besides the arguments I have written to consider. It always depends on what you want to enforce, when and to whom 😉 Maximum technical flexibility would be my target...ensure 1:1 would be possible if you clearly define the |
Well, if others reviewers decide that the constraint should be changed, I'm not blocking. Anyway, this PR is red, but I haven't checked why. |
859bf4c
to
c0194e3
Compare
@pedrobaeza |
…ode is In Austria we have several zipcodes for the same name and therefore this constraint would make this module unusable, especially in relation to the current Odoo Core implementation where this field is still used and a 1:1 relation should be possible at least even if we try to establish a normalization and a 1:n relation in the long run
c0194e3
to
15f23f5
Compare
|
Sorry, but the test say something else otherwise I would not have gone down this road... |
Well, I'm just pointing the problem by my experience on that, and seeing that you need to explicitly set the field with "" instead of accepting the default null. |
If we want to avoid that we could set a |
I have already explained why |
As said, the ORM does not make "" to null and based on this it should work...it does not work if it is null, so I can imagine to set the default that it will never happen that it will become null somewhere. If you agree I'll do that and we get it done... |
And what happen with existing records with NULL? |
The constraint can't be set...this is what Odoo does afaik. EDIT: but true, that is a reasonable question...damn it 🤣 |
But then it will break all the existing installations... That's why I'm not liking too much to add this. Adding a migration script that turns NULL to "" will avoid it initially, but I'm not sure if all the existing modules that feed these models will do it correctly. |
Is there an upgrade hook we could use? |
Yes, migration scripts can handle it. More or less this code: env.cr.execute("UPDATE res_city SET zipcode = '' WHERE zipcode IS NULL") |
What is the problem with just leaving zip in the model NULL? That is not change anything in the module. Lots of things will break if you are forcing all existing code to fill a value, even if it is an empty string, in zip. As shown by your need to adapt the tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I set Request Changes, but actually I think this PR should be closed. It is simply not a good idea to add a column that can be NULL to an SQL constraint.
@NL66278 @pedrobaeza |
@wtaferner Adding extra required / NOT NULL fields in an inheriting module will definitely break a lot of stuff and basically should never be done. I simply do not see any advantage in implementing the changes you are proposing. |
At least as informative purposes: @wtaferner you can put migration scripts in any version inside the Odoo major version for doing data massive changes. The upgrade engine is part of Odoo itself (it's not something of OpenUpgrade). Check this illustrative example: OCA/credit-control#86 |
@NL66278 Anyway, I would appreciate, if you could have given an example more explicit than "break a lot of stuff" and "should never be done", but I do agree that it is too heavy for a stable version and others, so I close the PR and move on. @pedrobaeza Thank you for all those who spent their valuable time for this PR too. Much appreciated. |
In Austria we have several zipcodes for the same name and therefore this constraint would make this module unusable...
Not sure though why it was introduced like it is, but I hope it was just an oversight.
Info: @wt-io-it